package cqrtplm.service.impl;

import com.hustcad.plm.basic.util.TyCommonExtUtil;
import com.hustcad.plm.pdm.common.util.CommonUtil;
import com.hustcad.plm.pdm.enumeration.mapper.TyplmEnumerationItemMapper;
import com.hustcad.plm.pdm.enumeration.model.dto.EnumerationItemAllLocalePropertyDTO;
import com.hustcad.plm.pdm.enumeration.service.impl.TyplmEnumerationItemServiceImpl;
import com.ty.basic.constant.CommonConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
@Primary
public class RTTyplmEnumerationItemServiceImpl extends TyplmEnumerationItemServiceImpl {

    @Autowired
    private TyplmEnumerationItemMapper typlmEnumerationItemMapper;

    public List<EnumerationItemAllLocalePropertyDTO> queryEnumerationInfoByDefid(List<BigInteger> enumDefOidList) {
        if (CollectionUtils.isEmpty(enumDefOidList)) {
            return new ArrayList<>();
        } else {
            String language = (String) CommonConstant.GET_LOCALE_PROPERTY_VALUE_LANGUAGE.get(TyCommonExtUtil.getFrontLanguage());
            List<List<BigInteger>> lists = CommonUtil.subObjectList(enumDefOidList, 800);
            List<EnumerationItemAllLocalePropertyDTO> localePropertyDTOList = new ArrayList<>();
            for(List<BigInteger> list : lists){
                localePropertyDTOList.addAll(this.typlmEnumerationItemMapper.queryEnumerationByDefidList(list, language));
            }
            return localePropertyDTOList.stream()
                    .filter(dto -> "displayName".equalsIgnoreCase(dto.getMetaDefName()))
                    .collect(Collectors.toList());
        }
    }

}
